﻿Imports Persistencia
Public Class ctrNcm

#Region "Variáveis"
    Private objNcm As New perNcm
#End Region

    Public Sub excluirNcm(ByVal sNcm As String)

        Try
            Me.objNcm.excluirNCM(sNcm)

        Catch ex As Exception

            Throw New Exception("Ocorreu um erro ao excluir as configurações de NCM. " & _
                                    Environment.NewLine & ex.Message)

        End Try

    End Sub

    Public Function selecionarNCM(ByVal sNCM As String) As DataTable

        Try
            Return Me.objNcm.selecionarNCM(sNCM)

        Catch ex As Exception

            Throw New Exception("Ocorreu um erro ao selecionar as configurações de NCM. " & _
                                    Environment.NewLine & ex.Message)

        End Try

    End Function

    Public Function salvarNCM(ByVal datNCM As DataTable) As Boolean
        Dim bRetorno As Boolean = True

        Dim sNCM As String
        Dim dIPI As Double
        Try

            Me.objNcm.excluirNCM("")

            For Each drNCM As DataRow In datNCM.Rows
                sNCM = Persistencia.Conversao.nuloParaVazio(drNCM.Item("NCM"))
                dIPI = Persistencia.Conversao.nuloParaZero(drNCM.Item("ipi"))

                Me.objNcm.inserirNCM(sNCM.Trim, dIPI)

            Next

        Catch ex As Exception
            bRetorno = False
            Throw New Exception("Ocorreu um erro ao salvar as informações de NCM. " & _
                                    Environment.NewLine & ex.Message)


        End Try

        Return bRetorno

    End Function

    Public Function atualizarNCMs() As DataTable

        Try

            Return Me.objNcm.atualizarNCMs

        Catch ex As Exception

            Throw New Exception("Ocorreu um erro ao atualizar os NCM´s. " & _
                                    Environment.NewLine & ex.Message)


        End Try
    End Function

End Class
